package com.uenpay.im.ui.old.activity.dynamic;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * dynamic detail
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * 
 */
public class GetDynamicDetailInvokeItem extends BaseHttpInvokeItem {
	public class GetDynamicDetailInvokeItemResult extends HttpInvokeResult {
		public ArrayList<DynamicEntity> dynamics = new ArrayList<DynamicEntity>();
	}

	public GetDynamicDetailInvokeItemResult getOutPut() {
		return (GetDynamicDetailInvokeItemResult) GetResultObject();
	}

	public GetDynamicDetailInvokeItem(String dynamicid) {
		String url = APIConfiguration.getBaseUrl()
				+ "Dynamic/Dynamic/getDynamicDetail?dynamicid=" + dynamicid + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GetDynamicDetailInvokeItemResult result = new GetDynamicDetailInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		JSONObject array = json.optJSONObject("data");
		if (array != null) {
			result.dynamics.add(DynamicSerializer.deserializeDynamicEntity(array));
		}

		return result;
	}
}
